#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int sort(vector<int>& nums, int l, int r, int k)
{
    if (l == r)  return nums[k];
    int t = nums[l], i = l - 1, j = r + 1;
    while (i < j)
    {
        do i++; while (nums[i] < t);
        do j--; while (nums[j] > t);
        if (i < j)
            swap(nums[i], nums[j]);
    }
    if (k <= j)  return sort(nums, l, j, k);
    else return sort(nums, j + 1, r, k);
}

int findKthLargest(vector<int>& nums, int k) {
    int n = nums.size();
    return sort(nums, 0, n - 1, n - k);
}

int main()
{
    vector<int> v = { 3,2,1,5,6,4 };
    findKthLargest(v,2);
    return 0;
}